import 'package:dartx/dartx.dart';
import 'package:get/get.dart';
import 'package:sgy_flutter/extensions/get.dart';

class AdjustZeroSuccessLogic extends GetxController {

  var currentRecord = "".obs;
  var lastRecord = "".obs;

  @override
  void onReady() async{
    if (bleManager.deviceModel?.isDoubleSlide == true || rightBleManager.deviceModel?.isDoubleSlide == true){
      List<Pair<int, String>>? left;
      try{
        left = await bleManager.fetchAdjustZeroRecord();
      }catch(e){

      }
      List<Pair<int, String>>? right;
      try{
        right = await rightBleManager.fetchAdjustZeroRecord();
      }catch(e){

      }


      currentRecord("L:${result(left?.first.first)} R:${result(right?.first.first)}");
      lastRecord("L:${result(left?[1].first)} R:${result(right?[1].first)}");
    }else{
      if (await bleManager.ensureDeviceConnected()) {
        bleManager.fetchAdjustZeroRecord().then((value) {
          currentRecord("${result(value.first.first)}");
          lastRecord("${result(value[1].first)}");
        });
      }
    }

    super.onReady();
  }

  String result(int? code) {
    switch (code) {
      case 0xffff:
      case 0xfffe:
      case 0xfffd:
        return "校准失败".tr;
      case null:
        return "";
      default:
        return "$code";
    }
  }
}
